package com.bcu.cn.onlineexamsystem.studentmanage.mapper;

import com.bcu.cn.onlineexamsystem.studentmanage.controller.StudentProfileDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface StudentProfileMapper {
    
    /**
     * 根据用户ID查询学生个人信息
     */
    @Select("SELECT u.user_id, u.user_name, u.real_name, " +
            "COALESCE(u.email, '') as email, " +
            "COALESCE(u.phone, '') as phone, " +
            "COALESCE(c.class_name, '') as class_name, " +
            "COALESCE(GROUP_CONCAT(co.course_name SEPARATOR ', '), '') as course_names " +
            "FROM users u " +
            "LEFT JOIN classes c ON u.class_id = c.class_id " +
            "LEFT JOIN student_courses sc ON u.user_id = sc.student_id " +
            "LEFT JOIN courses co ON sc.course_id = co.course_id " +
            "WHERE u.user_id = #{userId} " +
            "GROUP BY u.user_id, u.user_name, u.real_name, u.email, u.phone, c.class_name")
    StudentProfileDTO getStudentProfile(@Param("userId") String userId);
    
    /**
     * 更新学生邮箱
     */
    @Update("UPDATE users SET email = #{email} WHERE user_id = #{userId}")
    int updateEmail(@Param("userId") String userId, @Param("email") String email);
    
    /**
     * 更新学生电话号
     */
    @Update("UPDATE users SET phone = #{phone} WHERE user_id = #{userId}")
    int updatePhone(@Param("userId") String userId, @Param("phone") String phone);
} 